package com.xxl.shoppingapp.ui.home;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.xxl.baselib.app.AppInit;
import com.xxl.shoppingapp.R;
import com.xxl.shoppingapp.base.BaseFragment;
import com.xxl.shoppingapp.ui.adapter.TabFragmentAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * @author xuelian.xiong 2018/4/10
 * @Package com.xxl.shoppingapp.ui.main
 * @Title: HomeFragment
 * @Description: (用一句话描述该文件做什么)
 * Copyright (c) 传化公路港物流有限公司版权所有
 * Create DateTime: 2018/4/10
 */
public class HomeFragment extends BaseFragment {


    @Bind(R.id.tabLayout)
    android.support.design.widget.TabLayout mTabLayout;
    @Bind(R.id.view_pager)
    ViewPager viewPager;

    public static final String[] sTitle = new String[]{"百货", "生鲜", "食品", "家电"};

    @Override
    protected int getLayout() {
        return R.layout.fragment_application;
    }

    @Override
    protected void initView(View view) {
        super.initView(view);
        setTitle(getString(R.string.application));
        initTab();
    }

    private void initTab() {
        mTabLayout.addTab(mTabLayout.newTab().setText(sTitle[0]));
        mTabLayout.addTab(mTabLayout.newTab().setText(sTitle[1]));
        mTabLayout.addTab(mTabLayout.newTab().setText(sTitle[2]));
        mTabLayout.addTab(mTabLayout.newTab().setText(sTitle[3]));

        mTabLayout.setupWithViewPager(viewPager);

        List<Fragment> fragments = new ArrayList<>();
        fragments.add(GoodsFragment.getInstance());
        fragments.add(FreshFragment.getInstance());
        fragments.add(FoodFragment.getInstance());
        fragments.add(ElectricalFragment.getInstance());

        TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager(), getActivity());
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(0);
    }


}
